#! /usr/bin/env python
# -*- coding: utf-8 -*-

# pylint: disable=missing-docstring, bare-except

import os

def get_show_size(size):
    if size < 1024:
        return f"{size}  B"
    size = size / 1024
    if size < 1024:
        return f"{size:.2f} KB"
    size = size / 1024
    if size < 1024:
        return f"{size:.2f} MB"
    size = size / 1024
    return f"{size:.2f} GB"

def get_file_size(path):
    try:
        return os.path.getsize(path)
    except:
        return 0

def get_dir_size(path):
    size = 0
    for root, _, files in os.walk(path):
        for file in files:
            size += get_file_size(os.path.join(root, file))
    return size

def main():
    cwd = os.getcwd()
    names = os.listdir(cwd)
    total = 0
    for name in names:
        path = os.path.join(cwd, name)
        if os.path.isfile(path):
            size = get_file_size(path)
            total += size
            size = get_show_size(size)
            print(f"%12s    - {name}" % size)
            continue
        size = get_dir_size(path)
        total += size
        size = get_show_size(size)
        print(f"%12s    d {name}" % size)
    total = get_show_size(total)
    print(f"Total {len(names)}: {total}")

if __name__ == "__main__":
    main()
